package com.podcstr.entity;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Comparator;

/**
 * @author azim
 * @since 5/13/13 
 */

@Entity
@Table(name = "tb_podcasts")
@NamedQueries({
        @NamedQuery(name = "tb_podcasts.findById", query = "SELECT p FROM Podcast p WHERE p.id =:id"),
        @NamedQuery(name = "tb_podcasts.findByName", query = "SELECT p FROM Podcast p WHERE p.name=:name"),
        @NamedQuery(name = "tb_podcasts.findAllPodcasts", query = "SELECT p FROM Podcast p")
})
public class Podcast extends PersistanceObject {

    @NotNull
    private String name;

    @NotNull
    @Size(max = 200)
    private String description;

    @NotNull
    private String tags;

    @NotNull
    private boolean accessable;

    @NotNull
    @OneToOne
    private MediaFile albumArt;

    @NotNull
    @OneToOne
    private MediaFile audio;

    @NotNull
    @OneToOne
    private User user;

    @OneToOne
    private Series series;

    @Transient
    public long rating = 0L;

    @NotNull
    @OneToOne
    private Category category;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getTags() {
        return tags;
    }

    public void setTags(String tags) {
        this.tags = tags;
    }

    public boolean isAccessable() {
        return accessable;
    }

    public void setAccessable(boolean accessable) {
        this.accessable = accessable;
    }

    public MediaFile getAlbumArt() {
        return albumArt;
    }

    public void setAlbumArt(MediaFile albumArt) {
        this.albumArt = albumArt;
    }

    public MediaFile getAudio() {
        return audio;
    }

    public void setAudio(MediaFile audio) {
        this.audio = audio;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Series getSeries() {
        return series;
    }

    public void setSeries(Series series) {
        this.series = series;
    }

    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    public long getRating() {
        return rating;
    }

    public void setRating(long rating) {
        this.rating = rating;
    }

    //Comparator methods

    public static Comparator<Podcast> CompareByName = new Comparator<Podcast>() {
        @Override
        public int compare(Podcast o1, Podcast o2) {

            return o1.getName().compareTo(o2.getName());
        }
    };

    public static Comparator<Podcast> CompareByDateCreated = new Comparator<Podcast>() {
        @Override
        public int compare(Podcast o1, Podcast o2) {

            return o1.getDateCreated().compareTo(o2.getDateCreated());
        }
    };

}
